<?php

	namespace org\tekuna\demo\weblog\action\admin;

	use org\tekuna\framework\filter\data\IntegerFilter;

	use org\tekuna\demo\weblog\manager\CommentManager;

	use \PDOException;
	
	use org\tekuna\demo\weblog\manager\ArticleManager;
	use org\tekuna\demo\weblog\ArticleKeyFilter;
	
	use org\tekuna\framework\request\Request;
	use org\tekuna\framework\response\http\FourOhFourResponse;
	use org\tekuna\framework\action\ActionEvent;
	
	use org\tekuna\plugin\simpletemplate\SimpleTemplateAction;
	
	
	class EditArticleAction extends SimpleTemplateAction {
		
		private
			$objArticleManager;
		
		protected
			$article;
		
		
		public function executeTemplate(ActionEvent $objActionEvent, Request $objRequest) {
			
			// set the filter for the article key
			$objActionEvent -> setPartFilter('articleId', new IntegerFilter());
			
			// get the article key param
			$iArticleId = $objActionEvent -> getUrlPart('articleId');
			
			// load article from DB
			try {
			
				$this -> article = $this -> objArticleManager -> findFirstWhere('id', $iArticleId);

				// set a new application title
				$this -> getApplicationContext() -> setAppTitle("Edit Article");
				
			}
			catch (PDOException $objException) {
				
				return new FourOhFourResponse($objRequest);
			}
		}
		
		public function setArticleManager(ArticleManager $objArticleManager) {
			
			$this -> objArticleManager = $objArticleManager;
		}
	}